package cn.edu.njuit.lesson9heros.service.impl;

import cn.edu.njuit.lesson9heros.myioc.MyComponent;
import cn.edu.njuit.lesson9heros.pojo.Team;
import cn.edu.njuit.lesson9heros.service.HeroService;
import cn.edu.njuit.lesson9heros.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@MyComponent(name="teamService")
@Service("teamService")
public class TeamServiceImpl implements TeamService {
    @Autowired
    HeroService heroService;
    @Override
    public Team getTeam(Team existTeam) {
        Integer[] existIds= {0,0,0,0,0};
        if(existTeam!=null){
            existIds[0]=existTeam.getTopHero().getHeroId();
            existIds[1]=existTeam.getSupportHero().getHeroId();
            existIds[2]=existTeam.getAdcHero().getHeroId();
            existIds[3]=existTeam.getMidHero().getHeroId();
            existIds[4]=existTeam.getJungleHero().getHeroId();
        }
        Team team=new Team();
        team.setAdcHero(heroService.getHeroByPosition("adc",existIds));
        //排除adc英雄
        team.setJungleHero(heroService.getHeroByPosition("jungle",team.getAdcHero().getHeroId()
                ,existIds[0],existIds[1],existIds[2],existIds[3],existIds[4]));
        //排除已选择的adc和刺客
        team.setMidHero(heroService.getHeroByPosition("mid",team.getAdcHero().getHeroId(),
                                                                        team.getJungleHero().getHeroId()
                ,existIds[0],existIds[1],existIds[2],existIds[3],existIds[4]));
        //排除已选择的adc、刺客、中路
        team.setSupportHero(heroService.getHeroByPosition("support",team.getAdcHero().getHeroId(),
                                                                                team.getJungleHero().getHeroId(),
                                                                                team.getMidHero().getHeroId()
                                                ,existIds[0],existIds[1],existIds[2],existIds[3],existIds[4]));
        //排除已选择的adc、刺客、中路、辅助
        team.setTopHero(heroService.getHeroByPosition("top",team.getAdcHero().getHeroId(),
                                                                        team.getJungleHero().getHeroId(),
                                                                        team.getMidHero().getHeroId(),
                                                                        team.getSupportHero().getHeroId()
                                                ,existIds[0],existIds[1],existIds[2],existIds[3],existIds[4]));
        return team;
    }
}
